<template>
  <div>
    <el-upload
      ref="upload"
      class="upload-demo"
      drag
      v-loading="uploading"
      element-loading-spinner="el-icon-loading"
      element-loading-text="文件正在上传.."
      :http-request="importBtnDownload"
      multiple
    >
      <el-icon class="el-icon--upload"><upload-filled /></el-icon>
      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <!-- <div class="el-upload__tip">文件格式支持: zip, tar.gz, tar, gz, pcap, pcapng, cap</div> -->
    </el-upload>
  </div>
</template>
<script setup>
import { uploadGameResource } from "@/api/business/game";
const { proxy } = getCurrentInstance();
const emit = defineEmits();

const props = defineProps({
  gameId: {
    type: String,
    required: true,
  },
});
const importBtnDownload = (params) => {
  let gameId = props.gameId;
  const fileData = new FormData();
  const file = params.file;
  console.log(file);
  fileData.append("file", file);
  fileData.append("gameId", gameId);
  uploadGameResource(fileData).then((res) => {
    if (res.code === 200) {
      emit("update:modelValue");
      proxy.$modal.msgSuccess("新增成功");
    } else {
      proxy.$modal.msgSuccess("新增失败");
    }
  });
};
</script>